define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
   $(document).on('change', ".typechange", function () {
        var val = $(this).val();
        if(val == 1){
             $(".type1").show();
             $(".type2").hide();
             $(".type3").hide();
        }else if(val == 2) {
              $(".type2").show();
             $(".type1").hide();
             $(".type3").hide();
        }else if(val == 3) {
             $(".type2").hide();
             $(".type1").hide();
             $(".type3").show();
        }
    }); 
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'ques/subject/index',
                    add_url: 'ques/subject/add/ids/'+volume_ids,
                    edit_url: 'ques/subject/edit',
                    del_url: 'ques/subject/del',
                    multi_url: 'ques/subject/multi',
                    table: 'ques_volume_subject',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                 queryParams: function (params) {
                    //这里可以追加搜索条件
                    var filter = params.filter ? JSON.parse(params.filter) : {}; //判断当前是否还有其他高级搜索栏的条件
                    var op = params.op ? JSON.parse(params.op) : {}; 
                    //这里可以动态赋值，比如从URL中获取admin_id的值，filter.admin_id=Fast.api.query('admin_id');
                    filter.volume_id = volume_ids;
                    op.volume_id = "=";
                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                },
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'weigh', title: __('Weigh'),sortable:true},
                        {field: 'name', title: __('Namee')},
                        {field: 'must_fil_text', title: __('是否必填')},
                             {field: 'type_text', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'publish_text', title: __('Publish'), operate:false },
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});